package com.ruoyi.service.impl;

import com.ruoyi.domain.FinanceOrder;
import com.ruoyi.mapper.FinanceMapper;
import com.ruoyi.service.FinanceService;
import com.ruoyi.service.JurisdictionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Map;

@Service
public class FinanceServiceImpl implements FinanceService {

    @Autowired
    FinanceMapper financeMapper;

    @Autowired
    JurisdictionService jurisdictionService;

    @Override
    public List<Map> getOrderList(Map map) {
        map = getParam(map);
        map.put("jurisdiction",jurisdictionService.getHotelDataPermissionsAndCompleteSQL());
        return financeMapper.getOrderList(map);
    }

    @Override
    public Map getTotalData(Map map) {
        map.remove("pageNum");
        map.remove("pageSize");
        map = getParam(map);
        map.put("jurisdiction",jurisdictionService.getHotelDataPermissionsAndCompleteSQL());
        Map totalData = financeMapper.getTotalData(map);
        return totalData;
    }

    @Override
    public List<FinanceOrder> getFinanceListExport(Map map) {
        map = getParam(map);
        map.put("jurisdiction",jurisdictionService.getHotelDataPermissionsAndCompleteSQL());
        return financeMapper.getFinanceListExport(map);
    }

    public Map getParam(Map map){
        if (map.get("orderReqDateRange[0]") != null) {
            map.put("startReqTime", map.get("orderReqDateRange[0]").toString() + " 00:00:00");
        }
        if (map.get("orderReqDateRange[1]") != null) {
            map.put("endReqTime", map.get("orderReqDateRange[1]").toString() + " 23:59:59");
        }

        if (map.get("startTime[0]") != null) {
            map.put("rzStartTime", map.get("startTime[0]").toString());
        }
        if (map.get("startTime[1]") != null) {
            map.put("rzEndTime", map.get("startTime[1]").toString());
        }

        if (map.get("endTime[0]") != null) {
            map.put("ldStartTime", map.get("endTime[0]").toString());
        }
        if (map.get("endTime[1]") != null) {
            map.put("ldEndTime", map.get("endTime[1]").toString());
        }
        return map;
    }
}
